<?php

require_once(sfConfig::get('sf_lib_dir').'/filter/base/BaseFormFilterPropel.class.php');

/**
 * Folder filter form base class.
 *
 * @package    alika
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormFilterGeneratedTemplate.php 16976 2009-04-04 12:47:44Z fabien $
 */
class BaseFolderFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'tree_left'          => new sfWidgetFormFilterInput(),
      'tree_right'         => new sfWidgetFormFilterInput(),
      'tree_parent'        => new sfWidgetFormFilterInput(),
      'scope'              => new sfWidgetFormFilterInput(),
      'name'               => new sfWidgetFormFilterInput(),
      'alias'              => new sfWidgetFormFilterInput(),
      'description'        => new sfWidgetFormFilterInput(),
      'created_at'         => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => true)),
      'user_id'            => new sfWidgetFormPropelChoice(array('model' => 'sfGuardUser', 'add_empty' => true)),
      'view'               => new sfWidgetFormFilterInput(),
      'count'              => new sfWidgetFormFilterInput(),
      'custom_int'         => new sfWidgetFormFilterInput(),
      'custom_int2'        => new sfWidgetFormFilterInput(),
      'type_id'            => new sfWidgetFormPropelChoice(array('model' => 'TypeMaterial', 'add_empty' => true)),
      'photo_path'         => new sfWidgetFormFilterInput(),
      'seo_title'          => new sfWidgetFormFilterInput(),
      'seo_description'    => new sfWidgetFormFilterInput(),
      'seo_keyword'        => new sfWidgetFormFilterInput(),
      'is_last'            => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'baner2_folder_list' => new sfWidgetFormPropelChoice(array('model' => 'Baner', 'add_empty' => true)),
      'folder2tag_list'    => new sfWidgetFormPropelChoice(array('model' => 'Tag', 'add_empty' => true)),
      'mat2_folder_list'   => new sfWidgetFormPropelChoice(array('model' => 'Material', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'tree_left'          => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'tree_right'         => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'tree_parent'        => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'scope'              => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'name'               => new sfValidatorPass(array('required' => false)),
      'alias'              => new sfValidatorPass(array('required' => false)),
      'description'        => new sfValidatorPass(array('required' => false)),
      'created_at'         => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'user_id'            => new sfValidatorPropelChoice(array('required' => false, 'model' => 'sfGuardUser', 'column' => 'id')),
      'view'               => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'count'              => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'custom_int'         => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'custom_int2'        => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'type_id'            => new sfValidatorPropelChoice(array('required' => false, 'model' => 'TypeMaterial', 'column' => 'id')),
      'photo_path'         => new sfValidatorPass(array('required' => false)),
      'seo_title'          => new sfValidatorPass(array('required' => false)),
      'seo_description'    => new sfValidatorPass(array('required' => false)),
      'seo_keyword'        => new sfValidatorPass(array('required' => false)),
      'is_last'            => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'baner2_folder_list' => new sfValidatorPropelChoice(array('model' => 'Baner', 'required' => false)),
      'folder2tag_list'    => new sfValidatorPropelChoice(array('model' => 'Tag', 'required' => false)),
      'mat2_folder_list'   => new sfValidatorPropelChoice(array('model' => 'Material', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('folder_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addBaner2FolderListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(Baner2FolderPeer::FOLDER_ID, FolderPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(Baner2FolderPeer::BANER_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(Baner2FolderPeer::BANER_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function addFolder2tagListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(Folder2tagPeer::FOLDER_ID, FolderPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(Folder2tagPeer::TAG_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(Folder2tagPeer::TAG_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function addMat2FolderListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(Mat2FolderPeer::FOLDER_ID, FolderPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(Mat2FolderPeer::MATERIAL_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(Mat2FolderPeer::MATERIAL_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Folder';
  }

  public function getFields()
  {
    return array(
      'id'                 => 'Number',
      'tree_left'          => 'Number',
      'tree_right'         => 'Number',
      'tree_parent'        => 'Number',
      'scope'              => 'Number',
      'name'               => 'Text',
      'alias'              => 'Text',
      'description'        => 'Text',
      'created_at'         => 'Date',
      'user_id'            => 'ForeignKey',
      'view'               => 'Number',
      'count'              => 'Number',
      'custom_int'         => 'Number',
      'custom_int2'        => 'Number',
      'type_id'            => 'ForeignKey',
      'photo_path'         => 'Text',
      'seo_title'          => 'Text',
      'seo_description'    => 'Text',
      'seo_keyword'        => 'Text',
      'is_last'            => 'Boolean',
      'baner2_folder_list' => 'ManyKey',
      'folder2tag_list'    => 'ManyKey',
      'mat2_folder_list'   => 'ManyKey',
    );
  }
}
